package org.example.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.example.annotation.State;

import java.lang.annotation.Annotation;

//泛型表示给那个注解提供校验规则,检验的数据类型
public class StateValidation implements ConstraintValidator<State,String> {

    /**
     * @param s 将来要检验的数据
     * @param constraintValidatorContext constraintValidatorContext
     * @return 检验不通过false 检验通过true
     */
    @Override
    public boolean isValid(String s,
                           ConstraintValidatorContext constraintValidatorContext) {
        if(s==null){
            return false;
        }
        if(s.equals("0")||s.equals("1")){
            return true;
        }
        return false;
    }
}
